package homework.yuandan.service.impl;

import homework.yuandan.beans.Movie;
import homework.yuandan.common.ResponseEnum;
import homework.yuandan.common.vo.ResultVO;
import homework.yuandan.exception.AppException;
import homework.yuandan.mapper.MovieMapper;
import homework.yuandan.service.MovieService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 作者:49293
 * 时间:2021/1/3-14:07
 * @author 49293
 */
@Service
public class MovieServiceImpl implements MovieService {
    @Resource
    MovieMapper movieMapper;
    @Override
    public ResultVO<List<Movie>> viewNowPlaying() {
        List<Movie> movies = movieMapper.isShowing();
        if (movies.size() == 0){
            throw new AppException(ResponseEnum.NOW_PLAYING_EMPTY);
        }
        ResultVO<List<Movie>> resultVO = new ResultVO(ResponseEnum.SUCCESS_SERVER,movies);
        return resultVO;
    }

    @Override
    public ResultVO<List<Movie>> viewComingPlay() {
        List<Movie> movies = movieMapper.comingSoon();
        if (movies.size() == 0){
            throw new AppException(ResponseEnum.COMING_PLAYING_EMPTY);
        }
        ResultVO<List<Movie>> resultVO = new ResultVO(ResponseEnum.SUCCESS_SERVER,movies);
        return resultVO;
    }

    @Override
    public ResultVO<Movie> viewInfo(Integer movieId) {
        Movie info = movieMapper.getInfo(movieId);
        if (info == null){
            throw new AppException(ResponseEnum.MOVIE_ID_NO_FOUND);
        }
        ResultVO<Movie> resultVO = new ResultVO(200,"success",info);
        return resultVO;
    }
}
